package com.yanqu.road.logic.activity.foxcard.game.spell;

import com.yanqu.road.entity.activity.foxcard.FoxHandCard;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;

import java.util.ArrayList;
import java.util.List;

/**
 * 摧毁选定的手牌
 */
public class FoxCardSpellUse8 extends FoxCardSpellUseBase{
    @Override
    protected boolean spellUse(FoxCardGameLogic gameLogic) {
        int num = spellConfig.getParamList().get(0);
        int targetNum = targetIdList.size();
        if (targetNum <= 0 || targetNum > num) {
            return false;
        }

        List<FoxHandCard> triggerCards = new ArrayList<>();
        for (Integer handCardId : targetIdList) {
            FoxHandCard foxHandCard = gameLogic.getGameData().getHandCards().stream().filter(handCard -> handCard.getId() == handCardId).findFirst().orElse(null);
            if (foxHandCard == null) {
                return false;
            }
            triggerCards.add(foxHandCard);
        }

        if (triggerCards.isEmpty()) {
            return false;
        }

        gameLogic.destroyHandCards(triggerCards);
        return true;
    }
}
